package com.gx.mxbbx.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gx.mxbbx.dao.RuralCMSOfficeMapper;
import com.gx.mxbbx.po.RuralCMSOffice;
import com.gx.mxbbx.service.RuralCMSOfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.util.List;

@Service
@Transactional
public class RuralCMSOfficeServiceImpl implements RuralCMSOfficeService {
    @Autowired
    private RuralCMSOfficeMapper ruralCMSOfficeMapper;

    public PageInfo<RuralCMSOffice> getRuralCMSOfficeList(Integer currentPage, Integer limit, String officeName) {
        //利用PageHelper分页查询 注意：这个一定要放查询语句的前一行,否则无法进行分页,因为它对紧随其后第一个sql语句有效
        PageHelper.startPage(currentPage, limit);
        List<RuralCMSOffice> list = ruralCMSOfficeMapper.getRuralCMSOfficeList(officeName);
        PageInfo<RuralCMSOffice> pageInfo = new PageInfo<RuralCMSOffice>(list);
        return pageInfo;
    }

    public void officeadd(RuralCMSOffice ruralCMSOffice) {

        ruralCMSOffice.setCreateTime(new Timestamp(System.currentTimeMillis()));
        ruralCMSOffice.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        ruralCMSOfficeMapper.officeadd(ruralCMSOffice);
    }

    public void officedelete(Integer id) {
        ruralCMSOfficeMapper.officedelete(id);
    }

    public RuralCMSOffice officeopenEdit(Integer id) {
        RuralCMSOffice ruralCMSOffice = ruralCMSOfficeMapper.officeopenEdit(id);
        return ruralCMSOffice;
    }

    public void officeedit(RuralCMSOffice ruralCMSOffice) {
        ruralCMSOffice.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        ruralCMSOfficeMapper.officeedit(ruralCMSOffice);
    }

}
